package db_main

import (
	"errors"
	"fmt"
	"gorm.io/gorm"
	"longmen/server/config/global"
	"longmen/server/pkg/common/helper/util"
	"longmen/server/pkg/db/mysql"
	"longmen/server/pkg/db/mysql/models/models_main"
)

func GetGroupChatDeleteList(param map[string]interface{}, order string, page, size int) ([]*models_main.GroupChatDelete, error) {
	fName := "GetGroupChatDeleteList"
	o := make([]*models_main.GroupChatDelete, 0)
	table := mysql.GetRTable(&models_main.GroupChatDelete{})
	mysql.Condition(table, param, "", order, page, size)
	err := table.Find(&o).Error
	if err != nil {
		err = fmt.Errorf("%s%s", util.Convert(fName), err.Error())
	}
	return o, err
}

func GetGroupChatDelete(param map[string]interface{}) (*models_main.GroupChatDelete, error) {
	fName := "GetGroupChatDelete"
	o := &models_main.GroupChatDelete{}
	table := mysql.GetRTable(&models_main.GroupChatDelete{})
	mysql.Condition(table, param, "", "create_stamp desc", 0, 0)
	err := table.First(o).Error
	if errors.Is(err, gorm.ErrRecordNotFound) {
		return o, nil
	}
	if err != nil {
		err = fmt.Errorf("%s%s", util.Convert(fName), err.Error())
	}
	return o, err
}

func InsertGroupChatDelete(GroupChatDelete *models_main.GroupChatDelete) error {
	fName := "InsertGroupChatDelete"
	err := global.GetX().Create(GroupChatDelete).Error
	if err != nil {
		return fmt.Errorf("%s%s", util.Convert(fName), err.Error())
	}
	return nil
}
